//
// prepSQL.h
// libprotea
// Tools Library for the Protea Project / SQL Query Generator for PREP
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

//prepSQL.h

#ifndef __PROTEA_PREPSQL_H__
#define __PROTEA_PREPSQL_H__


//#include "defns1.h"
#include "../defines.h"
#include "Database.h"
#include "DBInterface.h"

//#include "../SDK/ToolsInterface.h"

enum SQL_STMT_ALTER_type {
	ALTER_ADDFIELD,
	ALTER_DROPFIELD,
	ALTER_ADDCON,
	ALTER_DROPCON,
	ALTER_ADDTABLE,
	ALTER_DROPTABLE
};

class __EXPORT XCPrepSQLGen : public XCSQLGen {
	friend class XCSQLStatement;
public:
	XCPrepSQLGen( XCAppInterface* app );
	~XCPrepSQLGen();

	void	Clear();

	void	MakeCREATE		( XCBuffer* buf );
	void	MakeDROP		( XCBuffer* buf );

	void	MakeADDFIELD	( XCBuffer* buf, XCField* fld );
	void	MakeDROPFIELD	( XCBuffer* buf, XCField* fld );

	void	MakeADDCON		( XCBuffer* buf, buffer_db_relate* idbr, int count, XCAppInterface* app );
	void	MakeDROPCON		( XCBuffer* buf, buffer_db_relate* idbr, int count, XCAppInterface* app );

	void	CreateAUTONUMBER( XCBuffer* buf );
	void	RemoveAUTONUMBER( XCBuffer* buf );

	bool	MakeRENAME		( XCBuffer* buf, char* src, char* tgt, XCAppInterface* app );
	void	MakeFINALIZE	( XCBuffer* buf, XCField* fld, int mode );

	SQL_STMT_ALTER_type GetAlterType() { return AlterType; };
	const char* GetSource() { return source; };
	const char* GetTarget() { return target; };

	void SetRealApp( int number ) { real_app_num = number; };
	int GetRealApp() { return real_app_num; };

private:
//	void	GetDataType( XCField* fld, long fmt, XCDBDriverDescr* desc );
	SQL_STMT_ALTER_type AlterType;

	buffer_db_relate **dbr;		// Array of pointers to buffer_db_relate objects, 
	int dbrCount;				// handled the same way as fields, orders, etc.
	XCAppInterface *ConsApp;	// app used to add the constraints
	bool AutoNum;				// If we are to create/drop an autonumber
	char *source;				// These two are for table renames
	char *target;
	long real_app_num;			// Real application number
};

#endif

